<?php

namespace app\admin\model;

use think\Model;
use think\Db;


class Banner extends Model
{

    

    

    // 表名
    protected $name = 'banner';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'site_text',
        'jump_type_list_text',
        'switch_text'
    ];
    

    protected static function init()
    {
        self::afterInsert(function ($row) {
            $pk = $row->getPk();
            $row->getQuery()->where($pk, $row[$pk])->update(['weigh' => $row[$pk]]);
        });
    }

    
    public function getSiteList()
    {
        return ['1' => __('Site 1'), '2' => __('Site 2')];
    }

    public function getJumpTypeListList()
    {
        return ['0' => __('Jump_type_list 0'), '1' => __('Jump_type_list 1'), '2' => __('Jump_type_list 2'), '3' => __('Jump_type_list 3'), "4" => __('跳转咨询')];
    }

    public function getSwitchList()
    {
        return ['0' => __('Switch 0'), '1' => __('Switch 1')];
    }

    //咨询列表
    public function getConsultManageList()
    {
        $consult_manage = Db::name("consult_manage")->field("id, name")->select();
        if(!$consult_manage){
            return [];
        }

        $consult_manage = array_column($consult_manage, "name", "id");

        array_unshift($consult_manage, "无");

        return  $consult_manage;
    }


    public function getSiteTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['site']) ? $data['site'] : '');
        $list = $this->getSiteList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getJumpTypeListTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['jump_type_list']) ? $data['jump_type_list'] : '');
        $list = $this->getJumpTypeListList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getSwitchTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['switch']) ? $data['switch'] : '');
        $list = $this->getSwitchList();
        return isset($list[$value]) ? $list[$value] : '';
    }




}
